<?php
include "otamu_config.php";
$startTime = slog_time();

$db =& ADONewConnection('access');
	$dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\\SMPK.mdb;Uid=Administrator;Pwd=;";
	$db->Connect($dsn);
$db->SetFetchMode(ADODB_FETCH_ASSOC);

class Institusi extends ADOdb_Active_Record
{
	var $_table = "master_staff";
}


//MSACCESS => PSQL table
$master_staff_map = array(
	'NO_KP_PASSPORT' => 'nokp',
	'NO_STAF' => 'no_staf',
	'NAMA' => 'nama',
	'KOD_GELARAN' => 'kod_gelaran',
	'KOD_JANTINA' => 'kod_jantina',
	'KOD_KAUM' => 'kod_kaum',
	'ALAMAT' => 'alamat',
	'POSKOD' => 'poskod',
	'BANDAR' => 'bandar',
	'KOD_DAERAH' => 'kod_daerah',
	'KOD_NEGERI' => 'kod_negeri',
	'TEL_BIMBIT' => 'hp',
	'STATUS' => 'aktif',
	'KOD_INSTITUSI' => 'kod_institusi',
	'KOD_JAWATAN' => 'kod_jawatan',
	'TARIKH_MULA_BERKHIDMAT' => 'tarikh_mula_khidmat',
	'TARIKH_TAMAT_BERKHIDMAT' => 'tarikh_tamat_khidmat',	'KOD_KATEGORI_STAF' => 'kod_kategori',	
	'KOD_AKADEMIK' => 'kod_akademik',
	'KOD_TARAF' => 'kod_taraf',
	'KOD_GRED' => 'kod_gred'
);

//set wanted fields
$selected_field = "";
foreach ($master_staff_map as $k=>$v) {
	$arr[] = $k;
}
$selected_field = join(",",$arr);
//$rs = $db->Execute("SELECT $selected_field FROM SPK_STAFF_PROFIL");
$rs = $db->Execute("SELECT NAMA FROM SPK_STAFF_PROFIL");
echo "SELECT $selected_field FROM SPK_STAFF_PROFIL"; //exit;

//$rs = $db->Execute("SELECT $selected_field FROM SPK_SEKOLAH");
$i=0;	
while (!$rs->EOF) {
	$i++;

	$institusi = new Institusi();
	foreach ($master_staff_map as $k => $v) {
		echo "$i : $k => " .$rs->fields[$k] . "<br>\n";
		$institusi->$v = $rs->fields[$k];

		if ($rs->fields[$k] == 'NULL') {
			$institusi->$v = '0';
		}
	}
	

	if (!$institusi->save()) { 
		echo $institusi->ErrorMsg();exit;
		$_SESSION['flash'] = $institusi->ErrorMsg();
	}else {
		$_SESSION['flash'] = 'Institusi telah diwujudkan.';
	}

    $rs->MoveNext();
} 

    $totalTime = elog_time($startTime);
     echo  "Execution Time: $totalTime Seconds";

exit;


?>